package models

type Image struct {
	Model
	Src string `json:"src"`
	ZhName string `json:"zh_name"`
	EnName string `json:"en_name"`
}

func ExistImageByID(id int) bool {
	var content Image
	db.Select("id").Where("id = ?", id).First(&content)
	return content.ID > 0
}

func GetImages() (imgs  []Image) {
	db.Find(&imgs)
	return
}

func AddImage(src, zh_name, en_name string) bool {
	db.Create(&Image{
		Src: src,
		ZhName: zh_name,
		EnName: en_name,
	})
	return true
}

func DeleteImage(id int) bool {
	db.Where("id = ?", id).Delete(&Image{})
	return true
}

func UpdateImage(id int, data interface{}) bool {
	db.Model(&Image{}).Where("id = ?", id).Updates(data)
	return true
}